home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 134_01.zip / CORO.H < prev    next >
Text File  |  1993-06-12  |  2KB  |  76 lines

  1. /* Definitions for the C functions for coroutine management */
  2.  
  3. /* Function control vector (C_FCV_) */
  4.  
  5. /* The unique identifier for every coroutine is a pointer to its
  6.    function control vector (FCV).  This structure provides all the
  7.    necessary information to link two coroutines. Its format is as
  8.    follows:
  9.  
  10.     Offset    Symbol        Function
  11.     ======    ======        ========
  12.  
  13. fcv ---------->    cf_sp_        Coroutine stack pointer    ----------------+
  14.       2    cf_passer_    Pointer to passer's FCV            |
  15.       4    cf_caller_    Pointer to caller's FCV            |
  16.       6    cf_type_    Type of last invocation (see below)    |
  17.       8    cf_stksiz_    Size of stack area            |
  18.      10    cf_info_    User supplied data.
  19.      12            Space for coroutine's stack        |
  20.                   .                    .
  21.                   .                    .
  22.                   .                    .
  23. (TOS)      0    cs_bc_        Saved BC register content <-------------+
  24.       2    cs_pc_        PC where coroutine will resume
  25.       4    cs_passee_    Target coroutine of last control transfer
  26.       6    cs_passval_    Value passed on last "call"/"detach"/"resume"/
  27.                     "return"
  28.       .              .    
  29.       .              .
  30.       .              .
  31. cf_stksiz_+6            Location of initial entry to coroutine
  32. cf_stksiz_+8            Location of "c_start_" function that starts
  33.                 coroutine initially.
  34.  
  35.     The main coroutine is something of a special case; it uses the
  36. main "C" stack.  Only the first eight bytes of its FCV are meaningful.
  37. */
  38.  
  39. #define C_FCV struct c_fcv_    /* Poor man's typedef */
  40.  
  41. struct c_fcv_ {
  42.     char * cf_sp_;        /* Stack pointer */
  43.     C_FCV * cf_passer_;    /* "Passer" FCV address */
  44.     C_FCV * cf_caller_;    /* "Caller" FCV address */
  45.     int cf_type_;        /* Type of last invocation */
  46.     int    cf_stksiz_;    /* Size of stack area */
  47.     int cf_info_;        /* User specified information */
  48.     };
  49.  
  50. struct c_stktop_ {
  51.     int cs_bc_;        /* Saved BC register content */
  52.     char * cs_pc_;        /* PC to resume */
  53.     C_FCV * cs_passee_;    /* Last coroutine invoked */
  54.     int cs_passval_;    /* Value passed to it */
  55.     };
  56.  
  57. struct c_initstk_ {
  58.     int (* ci_initfn_);    /* Initial function to call */
  59.     int (* ci_start_);    /* Entry point of coroutine starter */
  60.     };
  61.  
  62.  
  63.  
  64. /*    Types of control transfer (cf_type_ field) */
  65.  
  66. #define CT_UNKNOWN    0    /* Unknown (never invoked via standard
  67.                    mechanism) */
  68. #define CT_CALL        1    /* C_CALL */
  69. #define CT_RESUME    2    /* C_RESUME */
  70. #define CT_DETACH    3    /* C_DETACH */
  71. #define CT_RETURN    4    /* Standard C function return caused
  72.                    implicit DETACH */
  73. V struct c_fcv_    /* Poor man's typedef */
  74.  
  75. struct c_fcv_ {
  76.     char * cf_sp_;        /*